import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:yt_devops/pages/site/site_device_list/access_device/views/infoHeaderView.dart';
import 'package:yt_devops/pages/site/site_setting/site_setting_base_info/widgets/item_widget.dart';
import 'package:yt_devops/resources/str_res_keys.dart';
import '../../../../components/app_bar/app_bar_widget.dart';
import '../../../../components/gaps.dart';
import '../../../../components/select_phone_widget.dart';
import '../../../../components/yt_button.dart';
import '../../../../components/yt_text_style.dart';
import '../../../../styles/styles.dart';
import 'access_device_controller.dart';

class AccessDevicePage extends GetView<AccessDeviceController> {
  AccessDevicePage({Key? key}) : super(key: key);

  @override
  final controller = Get.put(AccessDeviceController());

  final BrnFormItemConfig theme = BrnFormItemConfig(
      // formPadding: EdgeInsets.zero,
      // subTitlePadding:EdgeInsets.zero
      );

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
        onTap: () => FocusScope.of(context).unfocus(),
        child: GetBuilder<AccessDeviceController>(
          builder: (controller) => Scaffold(
              resizeToAvoidBottomInset: false,
              appBar: AppBarWidget.withRightActions(ResKey.addNewDevice.tr),
              body: Container(
                // color: Colour.white,
                child: Column(

                  children: [
                    Expanded(
                      child: ListView(
                          padding: EdgeInsets.fromLTRB(0, 0.h, 0, 50.h),
                          children: [
                            InfoHeaderView(controller.type),
                            Gaps.vGap10,

                            Container(
                              clipBehavior: Clip.hardEdge,
                              margin: const EdgeInsets.only(left: 16, right: 16),
                              decoration: BoxDecoration(
                                borderRadius: BorderRadius.circular(8),
                                color: Colors.white,
                              ),
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  Container(
                                    // color: Colors.red,
                                    margin: EdgeInsets.only(
                                        left: 16.w,
                                        right: 16.w,
                                        top: 16.h,
                                        bottom: 16.h),
                                    child: Text(
                                      ResKey.baseInfo.tr,
                                      style: ytTextStyle(
                                          fontSize: 18,
                                          fontWeight: FontWeight.w500),
                                    ),
                                  ),
                                  Container(
                                    height: 1,
                                    margin: const EdgeInsets.only(
                                        left: 16, right: 16),
                                    color: Colour.dividerColor,
                                  ),
                                  Container(
                                    color: Colour.white,
                                    child: ItemWidget(controller.titleList[1],
                                        controller.deviceTypeController,
                                        inputTextColor: Colour.mainTextColor,
                                        titleColor: Colour.mainTextColor,
                                        titleFont: 14,
                                        inputTextFont: 14,
                                        isShowRight: true,
                                        maxLines: 2,
                                        isShowText: true,
                                        isRequired: false,
                                        inputTextWidth: 200.w,
                                        hintString: ResKey.pleSelect.tr,
                                        clickCallBack: () async {
                                          controller.chooseDeviceType();
                                        }),
                                  ),
                                  Container(
                                    color: Colour.white,
                                    child: ItemWidget(controller.titleList[2],
                                        controller.deviceModelController,
                                        inputTextColor: Colour.mainTextColor,
                                        titleColor: Colour.mainTextColor,
                                        titleFont: 14,
                                        inputTextFont: 14,
                                        inputTextWidth: 200.w,
                                        isShowRight: true,
                                        isRequired: false,
                                        maxLines: 2,
                                        isShowText: true,
                                        hintString: ResKey.pleSelect.tr,
                                        clickCallBack: () async {
                                          controller.chooseDeviceTypeDetail();
                                        }),
                                  ),
                                  Container(
                                    color: Colour.white,
                                    child: ItemWidget(
                                      controller.titleList[3],
                                      controller.deviceNameController,
                                      inputTextColor: Colour.mainTextColor,
                                      titleColor: Colour.mainTextColor,
                                      titleFont: 14,
                                      inputTextFont: 14,
                                      isShowRight: false,
                                      isRequired: false,
                                      isCanEdit: true,
                                      // hintString: ResKey.pleSelect.tr,
                                      textChangeCallBack: (text) {
                                        controller.checkCommitStatus();
                                      },
                                    ),
                                  ),
                                  Container(
                                    color: Colour.white,
                                    child: ItemWidget(
                                      controller.titleList[4],
                                      controller.deviceSnController,
                                      titleColor: Colour.mainTextColor,
                                      inputTextColor: Colour.mainTextColor,
                                      titleFont: 14,
                                      inputTextFont: 14,
                                      isShowRight: false,
                                      isCanEdit: true,
                                      isRequired: false,
                                      isShowDivider: false,
                                      textChangeCallBack: (text) {
                                        controller.checkCommitStatus();
                                      },
                                    ),
                                  ),
                                  Container(
                                    height: 10.h,
                                    color: Colour.backgroundColor,
                                  ),
                                ],
                              ),
                            ),
                      Container(
                          clipBehavior: Clip.hardEdge,
                          margin: const EdgeInsets.only(left: 16, right: 16),
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(8),
                            color: Colors.white,
                          ),
                          child: SelectPhotoWidget(
                                controller.deviceImageList, true, 3,
                                photoWidth: 96,
                                titleFontSize: 18,
                                titleString: ResKey
                                    .siteDeviceAccessDevicePicture
                                    .tr, (List<String> list) {
                              controller.deviceImageList = list;
                              controller.update();
                            }))
                          ]),
                    ),
                  ],
                ),
              ),
              bottomNavigationBar: Container(
                color: Colour.white,
                margin: EdgeInsets.only(top: 10.h),
                padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 16.h),
                child: SafeArea(
                  child: YtButton(
                    enabled: controller.btnCanClick,
                    color: controller.btnCanClick
                        ? Colour.primaryColor
                        : Theme.of(context).primaryColorLight,
                    text: ResKey.siteDeviceAccessNext.tr,
                    onPress: () => controller.gotoNext(),
                  ),
                ),
              )),
        ));
  }
}
